import { pageList } from '@/services/modules/page';
import { Effect, ImmerReducer, Reducer, Subscription } from 'umi';
import {pageListItem} from '../utils/page';

export interface IndexModelState {
  pageLists: pageListItem[];
}

export interface IndexModelType {
  namespace: 'page';
  state: IndexModelState;
  effects: {
    pageList: Effect;
  };
  reducers: {
    save: Reducer<IndexModelState>;
    // 启用 immer 之后
    // save: ImmerReducer<IndexModelState>;
  };
  subscriptions?: { setup: Subscription };
}

const IndexModel: IndexModelType = {
  namespace: 'page',

  state: {
    pageLists: [],
  },

  effects: {
    *pageList({ payload }, { call, put }) {
      let result = yield call(pageList,payload.page,payload.name,payload.path,payload.status)
       yield put({
         type:"save",
         payload:{
           pageList:result
         }
       })
    },
  },

  reducers: {
    save(state, action) {
      return {
        ...state,
        ...action.payload,
      };
    },

  },

};

export default IndexModel;